package com.gitee.xmhzzz.component.common.exception;


import com.gitee.xmhzzz.component.common.enums.ResponseCode;

/**
  * @ClassName
  * @Description
  * @Author wzq
  * @Date 2023/12/15 17:05
  * @Version 1.0
  */
public abstract class AbstractBusinessException extends RuntimeException
{
    private static final long serialVersionUID = 1L;
    
    private Integer responseCode = null;

    private Object[] args;

    private String msgTemplate;
    
    public AbstractBusinessException()
    {
        super();
    }

    public AbstractBusinessException(String msg)
    {
        super(msg);
        this.msgTemplate = msg;
    }
    
    public AbstractBusinessException(String msg, Integer responseCode)
    {
        this(msg);
        this.responseCode = responseCode;
    }
    
    public AbstractBusinessException(String msgTemplete, Object[] objs)
    {
        super(String.format(msgTemplete, objs));
        this.args = objs;
        this.msgTemplate = msgTemplete;
    }
    
    public AbstractBusinessException(Exception e)
    {
        super(e);
    }
    
    public AbstractBusinessException(String msg, Exception e)
    {
        super(msg, e);
        this.msgTemplate = msg;
    }

    public void setResponseCode(Integer responseCode)
    {
        this.responseCode = responseCode;
    }


    public int getResponseCode()
    {
        if(null == responseCode)
        {
            responseCode = ResponseCode.BUSINESS_EXCEPTION.getCode();
        }
        return responseCode;
    }

    public Object[] getArgs() {
        return args;
    }

    public String getMsgTemplate() {
        return msgTemplate;
    }
}
